#ifndef CAMERA_H
#define CAMERA_H

#include <QObject>
#include "opencv2/opencv.hpp"
#include "MvCameraControl.h"
#include <QDebug>


enum class CameraName{
    RobotArm,
    DataMatrix
};


class Camera : public QObject
{
   Q_OBJECT

private:

 const int robotarm_camera_ip = 141; //192.168.100.141
 const int datamatrix_camera_ip = 142; //192.168.100.142_    
       
public:
    Camera(QObject *parent = Q_NULLPTR);
    ~Camera();

    //
    bool turnOnCamera();
    //
    bool turnOffCamera();
    //
    bool GetImage(cv::Mat &image);

    bool set_exposure_time(int value);

    bool get_exposure_time(int& value);

    // print the discovered devices information to user
    bool PrintDeviceInfo(int index , MV_CC_DEVICE_INFO* pstMVDevInfo);
    
    //
    bool Initial_cameras();
    //
    bool turnOnCamera(CameraName camera_name);
    bool turnOffCamera(CameraName camera_name);

    bool turnOnDevice(CameraName camera_name, MV_CC_DEVICE_INFO* pstMVDevInfo);
    bool turnOffDevice(CameraName camera_name);
    
    bool GetImage(CameraName camera_name, cv::Mat & image);
    bool set_exposure_time(CameraName camera_name, int value);
    bool get_exposure_time(CameraName camera_name, int& value);

    int RGB2BGR( unsigned char* pRgbData, unsigned int nWidth, unsigned int nHeight );
    bool Convert2Mat(MV_FRAME_OUT_INFO_EX* pstImageInfo, unsigned char * pData);

    bool isOpen(CameraName camera_name);

private:
    int nRet = MV_E_NODATA;
    //void* handle = NULL;
    //unsigned char * pData = NULL;
    //MV_FRAME_OUT stImageInfo = { 0 };
    MV_CC_DEVICE_INFO_LIST stDeviceList;
    
    void* handle_robotarm = NULL;
    void* handle_datamatrix = NULL;
    std::map<CameraName, void*> DeviceHandle;
    std::map<CameraName, int> DeviceIndex;

    int robotarm_camera_index;
    int datamatrix_camera_index;

    cv::Mat current_Image;
    cv::Mat dataMatrix_Image;
};

#endif // CAMERA_H
